Se dispone del siguiente archivo CSV con información sobre los Air Bnb de la ciudad de Milán en 2019. En el dataset, solamente aparecen apartamentos completos. Con esta información, alumno debe realizar los siguientes procesos de analítica:

Cargar el archivo “Airbnb_Milan.csv” como dataframe:

df <- read.csv("Airbnb_Milan.csv")
df

Crear un nuevo dataframe que contenga únicamente las siguientes columnas: “host_is_superhost”, “host_identity_verified”, “bathrooms”, “bedrooms”, “daily_price”, “security_deposit”, “minimum_nights”, “number_of_reviews”, “review_scores_rating”.

short_df <- subset(df, select=c("host_is_superhost", "host_identity_verified",
            "bathrooms", "bedrooms", "daily_price", "security_deposit",
            "minimum_nights", "number_of_reviews", "review_scores_rating"))
short_df

Cambiar los factores de la variable “host_is_superhost” de 0, 1 a: “SI” y, “NO”. (investigar la función recode). Cambiar los factores de la variable “host_identity_verified” de 0, 1 a: “VERIFICA” y “NO VERIFICA”.

library(car)
## Loading required package: carData
short_df$host_is_superhost <- car::recode(short_df$host_is_superhost,"0='NO' ;1='SI'")
short_df$host_identity_verified <- car::recode(short_df$host_identity_verified,"0='NO VERIFICA' ;1='VERIFICA'")
short_df

Mostrar un resumen estadístico de los datos:

summary(short_df)
##  host_is_superhost  host_identity_verified   bathrooms         bedrooms     
##  Length:9322        Length:9322            Min.   : 1.000   Min.   : 0.000  
##  Class :character   Class :character       1st Qu.: 3.000   1st Qu.: 1.000  
##  Mode  :character   Mode  :character       Median : 3.000   Median : 1.000  
##                                            Mean   : 3.357   Mean   : 1.218  
##                                            3rd Qu.: 3.000   3rd Qu.: 2.000  
##                                            Max.   :17.000   Max.   :10.000  
##   daily_price     security_deposit minimum_nights    number_of_reviews
##  Min.   :  10.0   Min.   :  1.00   Min.   :  1.000   Min.   :  1.00   
##  1st Qu.:  59.0   1st Qu.:  1.00   1st Qu.:  1.000   1st Qu.:  4.00   
##  Median :  75.0   Median :  1.00   Median :  2.000   Median : 14.00   
##  Mean   : 103.7   Mean   : 21.71   Mean   :  3.205   Mean   : 39.64   
##  3rd Qu.: 107.0   3rd Qu.: 48.00   3rd Qu.:  2.000   3rd Qu.: 44.00   
##  Max.   :3000.0   Max.   :143.00   Max.   :365.000   Max.   :791.00   
##  review_scores_rating
##  Min.   : 20.00      
##  1st Qu.: 90.00      
##  Median : 95.00      
##  Mean   : 93.15      
##  3rd Qu.: 99.00      
##  Max.   :100.00

Filtrar el dataset por apartamentos cuyo mínimo de noches sea igual o menor que siete:

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
## 
##     recode
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
filter(short_df, minimum_nights<=7)

¿Cuál es el precio medio por día de una habitación en función de si el anfitrión tiene verificado o no su perfil?

tapply(short_df$daily_price, short_df$host_identity_verified, mean)
## NO VERIFICA    VERIFICA 
##    103.7127    103.7647

Quién tiene más número de reseñas, ¿un super host o no super host?

tapply(short_df$number_of_reviews, short_df$host_is_superhost, mean)
##       NO       SI 
## 30.87268 61.22391

Tiene más reseñas un super host.

Sobre la estadística anterior ¿quién tiene la puntuación media más alta?

tapply(short_df$review_scores_rating, short_df$host_is_superhost, mean)
##       NO       SI 
## 91.61382 96.92425

El super host tiene la puntuación media más alta.

Crea un vector categórico llamado “CATEGORÍA”, en función de que, si para la puntuación de las reseñas tiene de 0 a 49, sea “NO ACONSEJABLE”; de 50 a 75 sea “ESTÁNDAR”; y de 76 a 100 sea “TOP”.

short_df <- mutate(short_df, CATEGORIA = ifelse(review_scores_rating<=49, 'NO ACONSEJABLE', ifelse(review_scores_rating<=75, 'ESTÁNDAR', 'TOP')))
short_df

Mostrar las frecuencias de la variable CATEGORÍA.

table(short_df$CATEGORIA)
## 
##       ESTÁNDAR NO ACONSEJABLE            TOP 
##            263             42           9017

Obtener el histograma del precio por día.

hist(short_df$daily_price,
ylab = "Frecuencia",
xlab = "Valores",
main = "Histograma del precio por día",
col = "grey",
border = "blue")

Estudiar la relación entre los dormitorios y baños de forma gráfica.

library(ggplot2)
ggplot(short_df) +
geom_point(mapping = aes(bedrooms, bathrooms)) + geom_smooth(aes(bedrooms, bathrooms))
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

Mostrar un histograma del número de reseñas en función de si es un usuario verificado o no.

ggplot(short_df) +
geom_histogram(mapping = aes(number_of_reviews, fill = host_identity_verified), color = "black" )
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Mostrar un histograma por cada valor de “CATEGORÍA” en el que se enseñe la cuantía del depósito de seguridad en función de si el anfitrión es super host o no.

ggplot(short_df, mapping = aes(security_deposit)) +
geom_histogram(aes(security_deposit, fill=host_is_superhost), binwidth = 20) +
facet_wrap( ~ CATEGORIA)